from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import time
from selenium.webdriver.support.ui import Select
# 1. 手动指定 ChromeDriver 路径
from selenium.webdriver.common.by import By

service = Service('E:/devtools/Python/Python312/chromedriver.exe')  # 替换为实际路径

# 2. 创建浏览器实例
chrome = webdriver.Chrome(service=service)

try:
    # 3. 测试访问网页
    # chrome.get("https://www.baidu.com/")
    # input_tag = chrome.find_element(By.ID, 'kw')
    # input_tag.send_keys('Java')

    chrome.get("https://kyfw.12306.cn/otn/regist/init")
    select = Select(chrome.find_element(By.ID, 'cardType'))
    # 根据索引选择下拉选项
    # select.select_by_index(1)
    # 根据 value 选择下拉选项
    # select.select_by_value('B')
    # 根据可见文本选择下拉选项
    select.select_by_visible_text('外国护照')
    input("回车键关闭浏览器...")
except Exception as e:
    print(f"执行过程中出错: {e}")
finally:
    chrome.quit()
